//
//  GameLayer.h
//  CutCut
//
//  Created by Bullet Hermit on 12-11-2.
//  Copyright 紫竹飞燕 2012年. All rights reserved.
//


#import <GameKit/GameKit.h>
#import <Foundation/Foundation.h>
// When you import this file, you import all the cocos2d classes
#import "cocos2d.h"
#import "Box2D.h"
#import "GLES-Render.h"
#import "PolygonSprite.h"
#import "RayCastCallback.h"
#import "CCBlade.h"
#import "SimpleAudioEngine.h"
#import "constant.h"
//Pixel to metres ratio. Box2D uses metres as the unit for measurement.
//This ratio defines how many pixels correspond to 1 Box2D "metre"
//Box2D is optimized for objects of 1x1 metre therefore it makes sense
//to define the ratio so that your most common object type is 1x1 metre.

#define calculate_determinant_2x2(x1,y1,x2,y2) x1*y2-y1*x2
#define calculate_determinant_2x3(x1,y1,x2,y2,x3,y3) x1*y2+x2*y3+x3*y1-y1*x2-y2*x3-y3*x1
#define frandom (float)arc4random()/UINT64_C(0x100000000)
#define frandom_range(low,high) ((high-low)*frandom)+low
#define random_range(low,high) (arc4random()%(high-low+1))+low
#define midpoint(a,b) (float)(a+b)/2

// GameLayer
@interface GameLayer : CCLayer <GKAchievementViewControllerDelegate, GKLeaderboardViewControllerDelegate>
{
	CCArray* _cache;
	b2World* world;					// strong ref
	GLESDebugDraw *m_debugDraw;		// strong ref
    
    CGPoint _startPoint;
    CGPoint _endPoint;
    
    CCArray* _blades;
    CCBlade* _blade;
    float _deltaRemainder;
    RayCastCallback* _rayCastCallback;
    
    double _nextTossTime;
    double _tossInterval;
    int _queuedForToss;
    kTossType _currentTossType;  
    
    //HUD
    
    int _cuts;
    CCLabelTTF *_cutLabel;
    //Particles
    CCParticleSystemQuad *_bladeSparkle;
    //sound
    CDSoundSource* _swoosh;
    float _currentTime;
    float _previousTime;
    
    //Game Mode
    kGameMode gameMode;
    //Life Mode
    int _lives;
    //Time Mode
    int initTime;
    CCLabelTTF *_timeLabel;
    
    
}

// returns a CCScene that contains the GameLayer as the only child
+(CCScene *) scene;
+(CCScene*) sceneWithGameMode:(kGameMode)mode;
+(GameLayer*) nodeWithGameMode:(kGameMode)mode;
@property (nonatomic,retain) CCArray* cache;
@property (nonatomic,retain) CCArray* blades;
@property (nonatomic,retain) CDSoundSource* swoosh;
-(void) splitPolygonSprite:(PolygonSprite*) sprite;
-(b2Vec2*) arrangeVertices:(b2Vec2*) vertices vertexCount:(int) count;
-(BOOL) isVerticesAccept:(b2Vec2*) vertices vertexCount:(int) count;
-(b2Body*) createBodyWithPosition:(b2Vec2) position rotation:(float)rotation vertices:(b2Vec2*)vertices vertexCount:(int32)count density:(float)density friction:(float)friction restitution:(float)restitution;
-(void) pauseGame;
-(void) resumeGame;
-(void) backMenu;
@end
